<?php

class Control_DataAnalysis_rechargeLevelNum
{

    function rechargeLevelNum()
    {
        $nowGame = $game = MooForm::request('game');
        $platform = MooForm::request('platform');
        $nowChannel = $channel = MooForm::request('channel');
        $server = MooForm::request('server');
        $startDate = MooForm::request('startTime');
        $endDate = MooForm::request('endTime');

        if (!$startDate) {
            $startDate = date('Y-m-d', time());
        }
        if (!$endDate) {
            $endDate = date('Y-m-d', time());
        }

        $action = MooForm::request('action');
        MooView::set('action', $action);
        MooView::set('startDate', $startDate);
        MooView::set('endDate', $endDate);


        if ($action == 0) {
            MooView::render('rechargeLevelNum');
        } else if ($action == 1) {
            MooObj::get('Control_Data')->setPlatformData($game);

            $urlConf = MooConfig::get('main.dataAnalysis.recharge_level_num');

            $url = $urlConf . "&game=" . $game . "&beginDate=" . $startDate . "&endDate=" . $endDate;

            if ($platform) {
                $url = $url . "&platform=" . $platform;
            }
            if ($channel) {
                $url = $url . "&channel=" . $channel;
            }
            if ($server) {
                MooView::set('server', $server);
                $url = $url . "&server=" . $server; //入参名???
            }
            /*http://120.79.10.97:9031/recharge_level_num&game=h5_test&beginDate=2018-04-29&endDate=2018-05-23&platform=android&channel=h5-fd&server=test-1*/

            $servers = MooObj::get('Gm')->getServerListByGame($game);
            MooView::set('servers', $servers);

            //接口好了以后打开
            //$data = MooUtil::curl_send($url, null, 30);
            //$dataArr = MooJson::decode($data);
            //序号,充值等级区间,充值人数,充值金额,总充值金额.
            $dataArr = array(
                'code'=>0,
                'message'=>'OK',
                'totalRechargeNum'=>2000,
                'totalRechargeMoney'=>20000,
                'detail'=>array(
                    array('level'=>'L1-L5',
                          'rechargeNum'=>100,
                          'rechargeMoney'=> 1000,
                        ),
                    array('level'=>'L6-L10',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L11-L15',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L16-L20',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L21-L25',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L26-L30',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L31-L35',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L36-L40',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L41-L45',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L46-L50',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L51-L55',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L56-L60',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L61-L65',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L66-L70',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L71-L75',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L76-L80',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L81-L85',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L86-L90',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L91-L95',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    ),
                    array('level'=>'L96-L100',
                        'rechargeNum'=>100,
                        'rechargeMoney'=> 1000,
                    )
                )
                );
            /*{"code":"0","message":"OK","totalRechargeNum":"2000","totalRechargeMoney":"20000","detail":[{"level":"L1-L5","rechargeNum":"100","rechargeMoney":"1000"},{"level":"L6-L10","rechargeNum":"100","rechargeMoney":"1000"},{"level":"L11-L15","rechargeNum":"100","rechargeMoney":"1000"},{"level":"L16-L20","rechargeNum":"100","rechargeMoney":"1000"},...]}*/
            if ($dataArr) {
                foreach ($dataArr['detail'] as $key => $value){
                    $rechargeNumPercent = floor(($value['rechargeNum']/$dataArr['totalRechargeNum'])*10000)/10000*100;//人数占比
                    $rechargeMoneyPercent = floor(($value['rechargeMoney']/$dataArr['totalRechargeMoney'])*10000)/10000*100;//金额占比
                    $preRechargeMoney = floor(($value['rechargeNum']/$value['rechargeMoney'])*10000)/10000*100;//区间人均
                    $dataArr['detail'][$key]['rechargeNumPercent'] = $rechargeNumPercent."%";
                    $dataArr['detail'][$key]['rechargeMoneyPercent'] = $rechargeMoneyPercent."%";
                    $dataArr['detail'][$key]['preRechargeMoney'] = $preRechargeMoney."%";
                }
            }

            if ($platform) {
                MooView::set('platform', $platform);
            }
            if ($channel) {
                MooView::set('channel', $nowChannel);
            }

            MooView::set('nowGame', $nowGame);
            MooView::set('dataArr', $dataArr);
            MooView::render('rechargeLevelNum');
        } else {
            exit("error!");
        }
    }
}